package sg.edu.nus.comp.icreate.ivletalk;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import sg.edu.nus.comp.icreate.ivletalk.module.MainActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class SplashActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
		setContentView(R.layout.activity_splash);
		try {
			FileInputStream file = openFileInput(User.USER_FILENAME);
			User.createInstance(file);
			if (User.isValid()) {
				Intent intent = new Intent(this, MainActivity.class);
				intent.putExtra(BaseActivity.EXTRA_NEED_REFRESH, true);
				startActivity(intent);
			} else
				startActivity(new Intent(this, LoginActivity.class));
		} catch (FileNotFoundException e) {
			startActivity(new Intent(this, LoginActivity.class));
		} catch (IOException e) {
			startActivity(new Intent(this, LoginActivity.class));
		}
		finish();
	}
}
